jQuery(document).ready(function() {
	$('#kit-search-more').on('click', function() {
		$('.kit-search-mored').toggle();
	});
	
	var col = [ 
		{
		checkbox: 'checkbox',
		},
        {
            title:'ID',
            field:'id',
            align: 'center',
            valign: 'middle'
        },
		{
			title:'外教名字',
			field:'name',
			align: 'center',
			valign: 'middle'
		},
		{
			title:'国籍',
			field:'nationality',
			align: 'center',
			valign: 'middle'
		},
		// {
		// 	title:'状态',
		// 	field:'state',
		// 	align: 'center',
		// 	valign: 'middle',
		// 	formatter:function(value,row,index){
		// 		var statue="在职";
		// 		if(row.state!=0){
		// 			statue="离职";
		// 		}
		// 		return statue;
		//
		// 	}
		// },
        {
            title:'状态',
            field:'status',
            align: 'center',
            valign: 'middle'
        },
		{
			title:'从属',
			field:'depence',
			align: 'center',
			valign: 'middle'
		},
        {
            title:'Zoom Id',
            field:'zoomid',
            align: 'center',
            valign: 'middle'
        },
        {
            title:'邮箱',
            field:'email',
            align: 'center',
            valign: 'middle'
        },
        {
            title:'加入时间',
            field:'createtime',
            align: 'center',
            valign: 'middle'
        },
		{
			title:'在读学员数',
			field:'leanCount',
			align: 'center',
			valign: 'middle'
		},
		{
			title:'试听进行人数',
			field:'tryListernCount',
			align: 'center',
			valign: 'middle'
		},
		{
			title:'编辑',
			formatter:function(value,row,index){
				return '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="setinfo(\''+row.uniqueid+'\')">信息管理</a>'+
				'<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="state(\''+row.uniqueid+'\')">状态</a>'+
				'<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="manger(\''+row.uniqueid+'\')">课程管理</a>'+
				'<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="tdate(\''+row.uniqueid+'\')">日程</a>'+
                    // '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="edit(\''+row.uniqueid+'\')">编辑</a>'+
                    '<a href="javascript:;" onclick="doDelete(\''+row.uniqueid+'\')" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i> 删除</a>';
			}
		}
	];

	//------------------------------------------加载列表
	$('#_table').bootstrapTable({
		url:baseUrl+'/teachers',
		'method': "GET",
		locale: 'zh-CN',
		detailView: false,
		sidePagination: "server", //服务端处理分页
		striped: true,//隔行变色
		undefinedText: "",
		pagination: true,
		singleSelect: false,
		pageSize: pageList[0],
		cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pageNumber: 1,
		pageList: pageList,
		search: false, //不显示 搜索框
		uniqueId: "uniqueid", //每一行的唯一标识，一般为主键列
		showColumns: false, //不显示下拉框（选择显示的列）
		undefinedText: '',
		columns: col,
		queryParams: function(params) {
			return {
				pageNum: this.pageNumber,
				pageSize: this.pageSize,
				sortOrder: params.order
			}
		},
		
	});

})
var check = function() {

}
var doDelete = function(id) {
//	var rows = $('#_table').bootstrapTable('getSelections');
//	if(rows == [] || rows == null || rows.length == 0) {
//		parent.layer.alert('请选择要编辑的数据！', {
//			skin: 'layui-layer-molv', //样式类名
//			closeBtn: 0,
//			anim: 4,
//			time: 2000
//		});
//		return;
//	}
//	if(rows.length != 1) {
//		parent.layer.alert('请选择单条数据进行编辑！', {
//			skin: 'layui-layer-molv', //样式类名
//			closeBtn: 0,
//			anim: 4,
//			time: 1800
//		});
//		return;
//	}
	$.ajax({
		type: "delete",
		url:baseUrl+ '/teachers/' +id,//+ rows[0].uniqueid,
		async: true,
		success: function(data) {
			alert(data.msg);
			$('#_table').bootstrapTable('refresh');
		}
	});
}
var setinfo= function (techerid){
	parent.layer.open({
		id:techerid+'info',
		maxmin: true,
		type: 2,
		area: modalArea,
        content: './views/Period.html?techerid=' + techerid,
		btn: ['保存', '取消'],
		yes: function(index, layero) {
            var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/teacherPeriods/savePeriods/',
				type: 'POST',
				data: data,//,teacherId:'1245745'
				dataType:"json",      
           		contentType:"application/json",
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
var insert = function() {
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/TeacherEdit.html',
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/teachers',
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}

//-----------------处理到这里了，编辑状态
//课程管理
var manger=function(tid){
	parent.layer.open({
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/teacher_manager.html?tid='+tid, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		btn: [ '关闭'],
		btn2: function(index, layero) {
		}
	});
}
//日程
var tdate=function(tid){
	parent.layer.open({
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/teacher_riCheng.html?tid='+tid, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		btn: [ '关闭'],
//		yes: function(index, layero) {
//			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
//			console.log(layero);
//			$.ajax({
//				url:'/teachers/state/'+tid,
//				type: 'POST',
//				data: data,
//				success: function(data) {
//					alert(data.msg);
//					parent.layer.close(index);
////					$('#_table').bootstrapTable('refresh');
//				}
//			});
//		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
var state=function(tid){
	parent.layer.open({
		maxmin: true,
		type: 2,
		area: ['600px', '250px'],
		content: './views/form/TeacherState.html?uniqueid='+tid, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+'/teachers/state/'+tid,
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
//					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
var edit = function() {
	var rows = $('#_table').bootstrapTable('getSelections');
	if(rows == [] || rows == null || rows.length == 0) {
		parent.layer.alert('请选择要编辑的数据！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 2000
		});
		return;
	}
	if(rows.length != 1) {
		parent.layer.alert('请选择单条数据进行编辑！', {
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0,
			anim: 4,
			time: 1800
		});
		return;
	}
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/TeacherEdit.html?uniqueid='+rows[0].uniqueid, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+'/teachers/'+rows[0].uniqueid,
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
